#include "Disparity.h"

Disparity::Disparity(CVImage& image1,CVImage& image2,double smooth)
{
	_image1=&image1;
	_image2=&image2;
	smoothness=smooth;
}

Disparity::~Disparity()
{
}


inline double Disparity::DataEnergy(uint x,uint y,int label)
{
	if (x+label>=_image2->width() || x+label<0)
		return 0;
	double ip1=(double)(((uint) _image1->Pixel(x,y,0))&(_image1->ibits()));
	double ip2=(double)(((uint) _image2->Pixel(x+label,y,0))&(_image2->ibits()));
	return (double)(ip1-ip2)*(ip1-ip2)/(1<<_image1->depth())/(1<<_image1->depth());
}

inline double Disparity::SmoothEnergy(int lp,int label)
{
	double lp1=(double)lp;
	return smoothness*((lp1==label)?0:1)/(1<<_image1->depth());
}
